[modbus] Modbus register array backed by bytes and other simplifications #8862
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Inspired by #8172 I reworked the modbus transport to use direct byte arrays to represent the data.
This is purely refactoring with the aim of reducing boilerplate byte manipulation/copying code in bindings. With the changes we do get boosted performance: with 45000 invocations to
extractStateFromRegisters
with varying inputs, the self time is dropped to 55% of original, total time to 80%. Naturally these type of performance gains are dwarfed by network I/O and other real time overheads.This has many benefits:
byte[]
using bitwise operationsbyte[]
fromModbusRegister[]
(essentially array of 16-bit data blocks, registers).In addition I brought in more general methods to work with the data:
extractXX
, e.g.extractSInt8
(extract 8-bit signed integer) working directly withbyte[]
data. Return type is directly smallest suitable java primitive such asbyte
,short
etc.ValueBuffer
interface that acts similar to java'sByteBuffer
but having specialized methods to extract different types of value types that are encountered with modbusFinally, simplifications & harmonization was made to how registers are converted to to numbers, and how commands are converted to bytes. I find the new conversion logic more readable.
The PR is splitted in two parts:
String
, notStringType